//
//  NSConditionLockDemo.m
//  JKThreadTest
//
//  Created by 王冲 on 2018/10/25.
//  Copyright © 2018年 JK科技有限公司. All rights reserved.
//

#import "NSConditionLockDemo.h"

@interface NSConditionLockDemo ()

@property(nonatomic,strong) NSConditionLock *conditLock;

@end

@implementation NSConditionLockDemo

-(instancetype)init{
    
    if (self = [super init]) {
        
        self.conditLock = [[NSConditionLock alloc]initWithCondition:1];
        
    }
    
    return self;
}

- (void)otherTest
{
    [[[NSThread alloc] initWithTarget:self selector:@selector(__One) object:nil] start];
    
    [[[NSThread alloc] initWithTarget:self selector:@selector(__Two) object:nil] start];
    
    [[[NSThread alloc] initWithTarget:self selector:@selector(__Three) object:nil] start];
}

- (void)__One
{
    [self.conditLock lockWhenCondition:1];
    NSLog(@"__One");
    
    [self.conditLock unlockWithCondition:2];
}

// 线程2
// 往数组中添加元素
- (void)__Two
{
    [self.conditLock lockWhenCondition:2];
    

    NSLog(@"__Two");
    
    [self.conditLock unlockWithCondition:3];
}

-(void)__Three{
    
    [self.conditLock lockWhenCondition:3];
    
    
    NSLog(@"__Three");
    
    [self.conditLock unlockWithCondition:4];
}

@end
